﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SPMS.Utility;
using SPMS.Log.Repository;

namespace SPMS.Log.Core
{
    /// <summary>
    /// 日志记录器工厂
    /// </summary>
    /// <remarks>用于创建日志记录器</remarks>
    /// <history>
    /// [zanezeng]               2009/10/19 11:28    创建
    /// </history>
    public sealed class LoggerFactory : ILoggerFactory
    {
        #region ---ILoggerFactory

        /// <summary>
        /// 创建指定名称的日志记录器
        /// </summary>
        /// <param name="name">日志记录器的名称</param>
        /// <param name="threshold">日志输出器允许输出的日志级别</param>
        /// <param name="repository">创建出来的日志记录器所属的日志存储器</param>
        /// <returns>创建的指定名称的日志记录器</returns>
        /// <remarks></remarks>
        /// <exception cref="ArgumentNullException"><paramref name="name"/>为Null或者为空字符串</exception>
        /// <exception cref="ArgumentNullException"><paramref name="repository"/>为Null</exception>
        /// <history>
        /// [zanezeng]               2009/10/14 11:54    创建
        /// </history>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2009/10/19 11:31    创建
        /// </history>
        public AbstractLogger CreateLogger( string name, Level threshold, ILoggingRepository repository )
        {
            //断言参数
            ArgumentAssert.AssertStringArgumentNotNullOrEmpty( name, "name" );
            ArgumentAssert.AssertArgumentNotNull( repository, "repository" );

            //返回创建的日志记录器
            return new Logger( name, threshold, repository );
        }

        #endregion

        #region ---Field

        /// <summary>
        /// 获得默认的工厂实例
        /// </summary>
        /// <value>默认的工厂实例</value>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2009/10/19 11:36    创建
        /// </history>
        public static ILoggerFactory Default
        {
            get
            {
                return DEFAULT_INSTANCE;
            }
        }

        #endregion

        #region ---Field

        /// <summary>
        /// 默认的工厂实例
        /// </summary>
        private static readonly ILoggerFactory DEFAULT_INSTANCE = new LoggerFactory();

        #endregion
    }
}
